package com.hboxs.asl.controller.asl.product;

import com.hboxs.asl.Filter;
import com.hboxs.asl.entity.Product;
import com.hboxs.asl.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Controller -- 商品搜索
 */
@Controller("productService")
@RequestMapping("/ps")
public class ProductSearchControl {
    @Resource(name = "productServiceImpl")
    private ProductService productService;


    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public String index(ModelMap model, HttpServletRequest request,String key){
        List<Product> products = null;
        List<Filter> filters = new ArrayList<>();
        //搜索条件
        filters.add(Filter.like("name","%"+key+"%"));
        //根据输入的信息搜索商品
        if(key!=null){
            //查找商品
            products = productService.findList(null,filters,null);
        }
        model.addAttribute("products",products);
        return "/yijing/html/search";
    }
}
